package com.coocaa.aries.jmeter.util;

import org.apache.commons.collections.CollectionUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author : bijiahao
 * @date : 2019/4/10.
 * @description:<p> </p>
 */
public class CmdExecLogUtil {


    private static Map<Integer, LinkedBlockingQueue<String>> log = new ConcurrentHashMap<>(1000);

    public static void add(Integer id, String info) {
        LinkedBlockingQueue<String> list = log.get(id);
        if (null == list) {
            list = new LinkedBlockingQueue<>(100);
        }
        list.offer(info);
        log.put(id, list);
    }


    public static LinkedBlockingQueue<String> listLog(Integer id) {
        LinkedBlockingQueue<String> list = log.get(id);
        return list;
    }

    /**
     * 是否包含指定信息
     *
     * @param id
     * @param info
     * @return
     */
    public static boolean isContainInfo(Integer id, String info) {
        LinkedBlockingQueue<String> list = log.get(id);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.contains(info);
        }
        return false;
    }

    /**
     * @param id
     */
    public static void remove(Integer id) {
        LinkedBlockingQueue<String> list = log.get(id);
        if (CollectionUtils.isNotEmpty(list)) {
            list.clear();
        }
    }
}
